﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace OpenLightGroup.Visualizers.Controls
{
    public partial class OrbsVisualizer : UserControl, IVisualizer
    {
        private Duration _animationDuration = new Duration(new TimeSpan(0, 0, 0, 0, 15));

        public OrbsVisualizer()
        {
            InitializeComponent();
        }


        #region IVisualizer Members

        public void LoadParameters(params object[] values)
        {

            //params not needed.

        }

        public void UpdateUI(SoundBite clip)
        {

            for (int i = 0; i < this.LayoutRoot.Children.Count; i++)
            {

                UIElement target = this.LayoutRoot.Children[i];

                double opacityValue = clip.FrequencyChannels[i] * 0.025;
                //(clip.FrequencyChannels[i] / byte.MaxValue) * 5;


                Storyboard board = new Storyboard();

                board.Children.Add(AnimationHelper.CreateOpacityAnimation
                    (target, opacityValue, _animationDuration, false));

                //board.Children.Add(AnimationHelper.CreateScaleXAnimation
                //    (target, 1.5, new Duration(new TimeSpan(0, 0, 0, 0, 10)), true));

                //board.Children.Add(AnimationHelper.CreateScaleYAnimation
                //   (target, 1.5, new Duration(new TimeSpan(0, 0, 0, 0, 10)), true));



                board.Begin();

            }

        }


        #endregion
    }
}
